<?php
/**
 * This is the model class for table "{{view_log}}".
 *
 * The followings are the available columns in table '{{view_log}}':
 * @property integer $id
 * @property string $module
 * @property integer $module_id
 * @property string $language_code
 * @property string $create_timezone
 * @property string $create_timestamp
 * @property string $create_datetime
 * @property string $create_date
 * @property string $create_time
 * @property integer $create_by
 * @property string $update_timezone
 * @property string $update_timestamp
 * @property string $update_datetime
 * @property string $update_date
 * @property string $update_time
 * @property integer $update_by
 */
class ViewLog extends ActiveRecord {

    public $moduleId_;
    public $module_;
    public $language_;

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return ViewLog the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{view_log}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('module_, moduleId_, language_', 'filter', 'filter'=>'trim'),
            array('module_', 'length', 'max'=>45, 'allowEmpty'=>false),
            array('moduleId_', 'numerical', 'integerOnly'=>true, 'allowEmpty'=>false),
            array('language_', 'length', 'max'=>10, 'allowEmpty'=>false),
            array('module_, moduleId_, language_', 'safe'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(

        );
    }
    
    protected function beforeSave(){
        if(parent::beforeSave()){
            if($this->isNewRecord){
                $this->module = strtolower($this->module_);
                $this->module_id = (int)$this->moduleId_;
                $this->language_code = $this->language_;

                $this->setCreateDateTime();
            }else{
                $this->setUpdateDateTime();
            }
            return true;
        }else
            return false;
    }
    
    protected function afterSave(){
        parent::afterSave();
        $this->saveBrowserLog();
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id);
        $criteria->compare('module_id', $this->ref_id);
        $criteria->compare('module', $this->module, true);

        return new ActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}